package io.renren.modules.jxgkphone.service.Impl;


import io.renren.modules.jxgkphone.dao.TeachingEvaluationMapper;
import io.renren.modules.jxgkphone.entity.EvaluationContent;
import io.renren.modules.jxgkphone.entity.EvaluationLevel;
import io.renren.modules.jxgkphone.entity.EvaluationType;
import io.renren.modules.jxgkphone.entity.TeachingEvaluation;
import io.renren.modules.jxgkphone.service.TeachingEvaluationService;
import io.renren.modules.jxgkphone.tempEntity.TempEvaluation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TeachingEvaluationServiceImpl implements TeachingEvaluationService {
    @Autowired
    TeachingEvaluationMapper teachingEvaluationMapper;
    public List<EvaluationContent> findAllEvaluationContent(){
        List<EvaluationContent> ec=teachingEvaluationMapper.findAllEvaluationContent();
        return ec;
    }
    public void InsertTeachingEvaluation (TeachingEvaluation te){
        teachingEvaluationMapper.InsertTeachingEvaluation(te);
    }

    @Override
    public Object findAllEvaluationContentMap() {
        List<EvaluationContent> evaluationContentList=teachingEvaluationMapper.findAllEvaluationContent();
        List<EvaluationType> evaluationTypeList = teachingEvaluationMapper.findAllEvaluationType();
        List<EvaluationLevel> evaluationLevelList=teachingEvaluationMapper.findAllEvaluationLevel();
        List<Map<String,Object>> tempType=new ArrayList<>();
        for(EvaluationType evaluationType:evaluationTypeList)/**类别*/
        {
            Map<String,Object> mapTempType=new HashMap<>();
            List<Map<String,Object>> tempLevel=new ArrayList<>();
            for(EvaluationLevel evaluationLevel:evaluationLevelList)/** 等级*/
            {
                if(evaluationLevel.getEvaluationTypeId().equals(evaluationType.getEvaluationTypeId()))
                {
                    Map<String,Object> mapTempEvaluation =new HashMap<>();
                    List<TempEvaluation> tempEvaluationList=new ArrayList<>();
                    for(EvaluationContent evaluationContent:evaluationContentList)/**内容*/
                    {
                        if( evaluationContent.getEvaluationTypeId().equals(evaluationType.getEvaluationTypeId())
                            &&evaluationContent.getEvaluationLevelId().equals(evaluationLevel.getEvaluationLevelId()))
                        {
                            TempEvaluation tempEvaluation=new TempEvaluation();
                            tempEvaluationList.add(tempEvaluation);
                            tempEvaluation.setId(evaluationContent.getEvaluationContentId());
                            tempEvaluation.setName(evaluationContent.getEvaluationContentName());
                        }
                    }
                    mapTempEvaluation.put(evaluationLevel.getEvaluationLevelName(),tempEvaluationList);
                    tempLevel.add(mapTempEvaluation);
                }
            }
            mapTempType.put(evaluationType.getEvaluationTypeName(),tempLevel);
            tempType.add(mapTempType);
        }
        return tempType;
    }
    public List<EvaluationType> findAllEvaluationType() {
        List<EvaluationType> et = teachingEvaluationMapper.findAllEvaluationType();
        return et;
    }
    public List<TeachingEvaluation> findEvaluationInfo(String teacher_id,
                                                String student_id,
                                                String course_id){
        return teachingEvaluationMapper.findEvaluationInfo(teacher_id,student_id,course_id);
    }
    public void deleteEvaluationInfo(String teacher_id,
                              String student_id,
                              String course_id){
        teachingEvaluationMapper.deleteEvaluationInfo(teacher_id,student_id,course_id);
    }
    public EvaluationContent findEvaluationContentById(String ecid){
        return  teachingEvaluationMapper.findEvaluationContentById(ecid);
    }

}